package com.qf.service.impl;

import com.qf.dao.StudentDao;
import com.qf.dto.ScheduleDto;
import com.qf.entity.Comment;
import com.qf.entity.Examtoo;
import com.qf.entity.Selecting;
import com.qf.service.StudentService;
import com.qf.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;


    @Override
    public R SelectList(String snumber) {

        return new R(0,"ok",studentDao.selectAll(snumber));
    }

    @Override
    public R Comment(Comment comment) {
        if(comment!=null) {
            if (studentDao.insert(comment) > 0) {
                return new R(0, "OK", null);
            } else {
                return new R(1, "FAIL", null);
            }
        }else {
            return new R(1, "FAIL", null);
        }
    }

    @Override
    public R selectScore(String snumber) {



        return new R(0,"ok",studentDao.selectScore(snumber));
    }

    @Override
    public R courseSelectInsert(String snumber, int courseId) {

        Selecting selecting = studentDao.selectselecting(snumber,courseId);

        if (snumber != null && courseId != 0 && selecting ==null) {

            if (studentDao.courseSelectInsert(snumber, courseId) > 0) {
                studentDao.updatecourse(courseId);
                return new R(0, "success", null);
            } else {
                return new R(1, "fail", null);
            }
        } else {
                    return new R(1, "你已经选过该课程了", null);
                }

    }

    @Override
    public R courseSelectAll() {
        return new R(0, "ok", studentDao.courseSelectAll());
    }

    @Override
    public R selectStudentInfo(int id) {
        return null;
    }

    @Override
    public R selectExam(String snumber) {
        if (snumber != null) {
            return new R(0, "success", studentDao.selectExam(snumber));
        } else {
            return new R(1, "fail", null);
        }
    }

    @Override
    public R selectExamtoo(String snumber) {

        return new R(0,"sussess",studentDao.selectExamtoo(snumber));
    }

    @Override
    public R signIn(int coursecount, String snumber, int courseId) {
        if (snumber != null & courseId != 0) {
            String tnumber = studentDao.selectTeacher(courseId);
            String flag = studentDao.selectSignIn(tnumber, courseId);
            if ("1".equals(flag)) {
                if (studentDao.booleanSign(coursecount, snumber, courseId) == null) {
                    return new R(0, "签到成功", studentDao.signIn(coursecount, snumber, courseId));
                }
                {
                    return new R(1, "请勿重复签到", null);
                }
            } else  {
                return new R(1, "老师未开启签到", null);
            }

        }
        return new R(1, "签到失败", null);
    }
}
